#include <bits/stdc++.h>
// 2025/02/03
// tag:
// Author: Zhang Muen
using namespace std;

int n, m, parents[40001], l[5001], r[5001];
bitset<5001> type;

class UF {
public:
    UF(int n)
    {
        for (int i = 1; i <= n * 2; i++)
            parents[i] = i;
    };

    int find(int i)
    {
        if (parents[i] != i)
            return parents[i] = find(parents[i]);
        return parents[i];
    }

    void un(int i, int j)
    {
        int ri = find(i), rj = find(j);
        if (ri == rj)
            return;
        parents[ri] = rj;
    }

    bool connected(int p, int q)
    {
        return find(p) == find(q);
    }
};

signed main()
{
    cin >> n >> m;
    string t;
    set<int> s;
    unordered_map<int, int> um;
    for (int i = 1; i <= m; i++) {
        cin >> l[i] >> r[i] >> t, l[i]--;
        if (t == "odd")
            type[i] = true;
        s.insert(l[i]), s.insert(r[i]);
    }
    UF uf(s.size() * 2);
    int cnt = 1;
    for (auto x : s)
        um[x] = cnt++;
    for (int i = 1; i <= m; i++) {
        int newl = um[l[i]], newr = um[r[i]];
        if (type[i] == true) {
            if (uf.connected(newl, newr)) {
                cout << i - 1;
                return 0;
            }
            uf.un(newl, newr + s.size());
            uf.un(newl + s.size(), newr);
        } else {
            if (uf.connected(newl, newr + s.size()) || uf.connected(newl + s.size(), newr)) {
                cout << i - 1;
                return 0;
            }
            uf.un(newl, newr);
            uf.un(newl + s.size(), newr + s.size());
        }
    }
    cout << m;
    return 0;
}